﻿using System;

namespace Hiver.Util
{
    /// <summary>
    /// 错误信息类
    /// </summary>
    public class Error
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="code">错误代码</param>
        /// <param name="exit">是否中止程序</param>
        public static void Show(int code, bool exit = true)
        {
            if (exit)
                throw new Exception(Error.GetErrorMsg(code));
            else
                Console.WriteLine(Error.GetErrorMsg(code));
        }

        /// <summary>
        /// 获得错误信息
        /// </summary>
        /// <param name="code">错误代码</param>
        /// <returns></returns>
        public static string GetErrorMsg(int code)
        {
            switch (code)
            {
                case 1:
                    return "application.yml配置文件不存在";
                case 2:
                    return "SqlSugar数据库配置错误";
                case 3:
                    return "MongoDB数据库配置错误";
                case 4:
                    return "Redis配置错误";
                case 5:
                    return "Redis无法Clear数据";
                case 6:
                    return "Redis无法Flush数据";
                case 7:
                    return "Windows自动服务配置错误";
                case 8:
                    return "RabbitMQ配置错误";
                default:
                    return "未知错误";
            }
        }
    }
}